// pages/doctor-consum-record/doctor-consum-record.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    recordList: [],
    pageNum: 1,
    pageSize: 10,
    hasMore: true,
    ajaxLoading: false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getRecordList();
  },

  getRecordList: function () {
    const t = this;
    if (!this.data.ajaxLoading) {
      this.setData({
        ajaxLoading: true
      });
      let { pageNum, pageSize, recordList } = this.data;
      app.request({
        url: 'doctor/beautyCoin/getListbeautyCoin',
        data: {
          type: 1,
          pageSize: pageSize,
          pageNo: pageNum
        },
        success: function (res) {
          let data = res.data;
          t.setData({
            ajaxLoading: false
          });
          wx.stopPullDownRefresh();
          if (data.length < pageSize) {
            t.setData({
              hasMore: false
            });
          }
          if (pageNum == 1) {
            t.setData({
              recordList: res.data
            });
          }
          else {
            let list = recordList.concat(res.data);
            t.setData({
              recordList: list
            })
          }
        }
      })
    }
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.setData({
      pageNum: 1
    });
    this.getRecordList();
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    let { hasMore } = this.data;
    if (hasMore) {
      this.setData({
        pageNum: this.data.pageNum + 1
      });
      this.getRecordList();
    }
    else {
      wx.showToast({
        title: '没有更多数据了',
        icon: 'none',
        duration: 1000
      });
    }
  },
})